package com.probiz.estore.common.model.catalog;

import org.apache.commons.lang.StringUtils;

import com.probiz.estore.common.model.catalog.base.ProductCategoryTbl;

/**
 * Model class for ProductCategory. Add not database mapped fileds in this class.
 * 商品目录
 */
public class ProductCategory extends ProductCategoryTbl {

    public final static Short	STATUS_ACTIVE	= (short) 1;
	public final static Short	STATUS_INACTIVE	= (short) 0;
	public final static Short	STATUS_DELETED	= (short) -1;
	public final static Integer	SORTORDER_DEFAULT_VALUE	= new Integer("9999");
	public final static Integer	ROOT_ID	= new Integer("1");//根目录id

    /**
     * Default Empty Constructor for class ProductCategory
     */
    public ProductCategory() {
        super();
    }

    /**
     * Default Key Fields Constructor for class ProductCategory
     * @param  in_categoryId 目录id
     */
    public ProductCategory(Integer in_categoryId) {
        super(in_categoryId);
    }

    /**
     * 定义实体的业务名取值
     * @return 实体业务名
     */
    public String getProductCategoryName() {
        if (categoryId == null)
            return "";
        else
            //返回一个指定有业务意义的属性值;
            //如：product的VO就用product.productName
            return this.categoryName;
    }

	/**
     * 获取完整的目录路径名 例：主页>电器>冰箱>海尔冰箱
	 * @return 完整的目录路径名
	 */
	public String getFullCategoryPathName() {
		if(StringUtils.isNotBlank(getParentFullCategoryPathName())){
			return getParentFullCategoryPathName()+">"+getCategoryName();
		}else{
			return getCategoryName();
		}
	}

	/**
     * 获取简单的目录路径名(不包含根) 例：电器>冰箱>海尔冰箱
	 * @return 简单的目录路径名(不包含根)
	 */
	public String getSimpleCategoryPathName(){
		StringBuffer categoryPathNameBuffer=new StringBuffer(100);
		ProductCategory parentCategory=this.getParent();
		while (parentCategory!=null && parentCategory.getCategoryId() !=1) {
			categoryPathNameBuffer.insert(0, ">");
			categoryPathNameBuffer.insert(0, parentCategory.getCategoryName());
			parentCategory=parentCategory.getParent();
		}
		String categoryPathName = categoryPathNameBuffer.toString();
		if(!StringUtils.isEmpty(categoryPathName))categoryPathName = categoryPathName.substring(0,categoryPathName.length()-1);
		if(StringUtils.isBlank(categoryPathName)) {
			return getCategoryName();
		}else{
			return categoryPathName+">"+getCategoryName();
		}
	}
	/**
     * 获取父目录完整的目录路径名 例：主页>电器>冰箱
	 * @return 父目录完整的目录路径名 
	 */
	public String getParentFullCategoryPathName(){
		StringBuffer categoryPathNameBuffer=new StringBuffer(100);
		ProductCategory parentCategory=this.getParent();
		while (parentCategory!=null) {
			categoryPathNameBuffer.insert(0, ">");
			categoryPathNameBuffer.insert(0, parentCategory.getCategoryName());
			parentCategory=parentCategory.getParent();
		}
		String categoryPathName = categoryPathNameBuffer.toString();
		if(!StringUtils.isEmpty(categoryPathName))categoryPathName = categoryPathName.substring(0,categoryPathName.length()-1);
		return categoryPathName;
	}



}
